package com.ztn.iot.zhonghaichi2.push;

import com.ztn.base.util.common.HttpClientTool;
import com.ztn.base.util.common.IdTool;
import com.ztn.base.util.common.JsonTool;
import com.ztn.base.util.common.TimeTool;
import com.ztn.iot.zhonghaichi2.properties.ZhcProperties;
import com.ztn.iot.zhonghaichi2.push.req.DataReq;
import com.ztn.iot.zhonghaichi2.push.req.PptnsData;
import com.ztn.iot.zhonghaichi2.push.req.RsvrsData;
import com.ztn.iot.zhonghaichi2.push.req.SeepagesData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Arrays;

@Slf4j
@Component
public class DataPushApi {

//    @Autowired
//    private ZhcProperties zhcProperties;
//
    public static final String URL = "http://" + ZhcProperties.IP + "/data/receive";
//
//    public void pushRain(int time, String siteCode, Double rainCount, Double hourRainCount, Double dayRainCount) {
//        if (!StringUtils.hasText(siteCode)) {
//            return;
//        }
//        final String date = TimeTool.timeStamp2Date(time);
//        DataReq.Item item = new DataReq.Item();
//        item.setPptn(Arrays.asList(PptnsData.builder()
//                        .drp(hourRainCount)
//                        .intv(1.00)
//                        .stcd(siteCode)
//                        .tm(date)
//                        .dyp(dayRainCount)
////                .pdr()
//                        .build()
//        ));
//        DataReq.DataItem dataDataItem = new DataReq.DataItem();
//        dataDataItem.setInsert(item);
//        DataReq dataReq = new DataReq();
//        dataReq.setTime(date);
//        dataReq.setToken(zhcProperties.getToken());
//        dataReq.setSysid(IdTool.getUUID());
//        dataReq.setAdcd(zhcProperties.getAdcd());
//        dataReq.setDatas(dataDataItem);
//        HttpClientTool.postJsonStrForStr(DataPushApi.URL, JsonTool.toJson(dataReq), null);
//
//    }
//
//    public void pushFlow(int time, String siteCode, Double speed, Double flow, Double dept, Double flowCount) {
//        if (!StringUtils.hasText(siteCode)) {
//            return;
//        }
//        final String date = TimeTool.timeStamp2Date(time);
//        DataReq.Item item = new DataReq.Item();
//        item.setSeepage(Arrays.asList(SeepagesData.builder()
//                        .stcd(siteCode)
//                        .tm(date)
//                        .q(flowCount)
//                        .z(dept)
////                .p()
//                        .build()
//        ));
//        DataReq.DataItem dataDataItem = new DataReq.DataItem();
//        dataDataItem.setInsert(item);
//        DataReq dataReq = new DataReq();
//        dataReq.setTime(date);
//        dataReq.setToken(zhcProperties.getToken());
//        dataReq.setSysid(IdTool.getUUID());
//        dataReq.setAdcd(zhcProperties.getAdcd());
//        dataReq.setDatas(dataDataItem);
//        String reqJson = JsonTool.toJson(dataReq);
//        log.info(reqJson);
//        String str = HttpClientTool.postJsonStrForStr(DataPushApi.URL, reqJson, null);
//        log.info(str);
//    }
//
//    public void pushWater(int time, String siteCode, Double waterDept, Double siteStorage, Double input, Double output, Double warnWaterDept) {
//        if (!StringUtils.hasText(siteCode)) {
//            return;
//        }
//
//        final String date = TimeTool.timeStamp2Date(time);
//
//        DataReq.Item item = new DataReq.Item();
//        item.setRsvr(Arrays.asList(RsvrsData.builder()
//                        .stcd(siteCode)
//                        .tm(date)
//                        .rz(waterDept)
//                        .inq(input)
//                        .w(siteStorage)
////                .blrz()
//                        .otq(output)
//                        .rwchrcd(5)
//                        .rwptn(6)
////                .inqdr()
//                        .msqmt(4).build()
//        ));
//        DataReq.DataItem dataDataItem = new DataReq.DataItem();
//        dataDataItem.setInsert(item);
//        DataReq dataReq = new DataReq();
//        dataReq.setTime(date);
//        dataReq.setToken(zhcProperties.getToken());
//        dataReq.setSysid(IdTool.getUUID());
//        dataReq.setAdcd(zhcProperties.getAdcd());
//        dataReq.setDatas(dataDataItem);
//        HttpClientTool.postJsonStrForStr(DataPushApi.URL, JsonTool.toJson(dataReq), null);
//
//
//    }
}
